home *** CD-ROM | disk | FTP | other *** search
- #include <OpenTransport.h> // open transport files
- #include <OpenTptAppletalk.h>
-
- OSStatus DoNegotiateReplyCntOption(EndpointRef ep, UInt32 replyCnt);
-
- /*
- Sample function to set the ATP_OPT_REPLYCNT option for an ATP
- endpoint. This function can also be used by PAP endpoints prior to
- connecting to a printer which replies with less than the default 8
- expected reply packets, AND does not set the EOM bit in the message.
- This function also demonstrates the use of the OTOptionManagement call.
-
- Unless explicitely defined by XTI, all Open Transport options
- use a kOTFourByteOptionSize buffer.
-
- Input
- EndpointRef ep - endpoint on which to set EOM option on
- UInt32 replyCnt - expected number of replies 1 - 8
-
- Return: kOTNoError indicates that the option was successfully negotiated
- OSStatus is an error if < 0, otherwise, the status field is
- returned and is > 0.
-
- */
- OSStatus DoNegotiateReplyCntOption(EndpointRef ep, UInt32 replyCnt)
-
- {
- UInt8 buf[kOTFourByteOptionSize]; // define buffer for fourByte Option size
- TOption* opt; // option ptr to make items easier to access
- TOptMgmt req;
- TOptMgmt ret;
- OSStatus err;
- Boolean isAsync = false;
-
- if ((replyCnt < 1) || (replyCnt > 8)) // preflight replyCnt
- return -1; // return -1 (err) if replyCnt is invalid
-
- opt = (TOption*)buf; // set option ptr to buffer
- req.opt.buf = buf;
- req.opt.len = sizeof(buf);
- req.flags = T_NEGOTIATE; // negotiate for rawmode option
-
- ret.opt.buf = buf;
- ret.opt.maxlen = kOTFourByteOptionSize;
-
-
- opt->level = ATK_ATP; // dealing with ATP level
- opt->name = ATP_OPT_REPLYCNT;
- opt->len = kOTFourByteOptionSize;
- opt->status = 0;
- *(UInt32*)opt->value = replyCnt; // set the desired option level, true or false
-
- if (OTIsSynchronous(ep) == false) // check whether ep sync or not
- {
- isAsync = true; // set flag if async
- OTSetSynchronous(ep); // set endpoint to sync
- }
-
- err = OTOptionManagement(ep, &req, &ret);
-
- if (isAsync == true) // restore ep state if necessary
- OTSetAsynchronous(ep);
-
- // if no error then return the option status value
- if (err == kOTNoError)
- {
- if (opt->status != T_SUCCESS)
- err = opt->status;
- else
- err = kOTNoError;
- }
-
- return err;
- }
-